<!--
 * @Descripttion: 核验审批
 * @version: 
 * @Author: wl
 * @Date: 2020-05-21 17:00:50
 * @LastEditors: wl
 * @LastEditTime: 2020-06-15 18:05:53
--> 
<template>
  <div>
    <page :asideShow="asideShow">
      <div slot="toolbar">
        <el-form :inline="true" :model="filters" label-width="90px" label-position="right">
          <el-form-item label="人员类型：">
            <div>
              <el-input
                class="normal"
                v-model="filters.corpName"
                clearable
                placeholder="请选择"
                @clear="handleClear"
              ></el-input>
              <!-- <template>
                  <unit-tree-data v-if="unitShow" @click="handleTreeClick" class="stat-search-box">12</unit-tree-data>
              </template>-->
            </div>
          </el-form-item>
          <el-form-item label="姓名：">
            <el-input class="normal" placeholder="请输入" clearable v-model="filters.username"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleQuery">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div slot="content">
        <el-table
        :header-cell-style="{ background: '#e7eaf0', color: '#606266' }"
          v-loading="loading"
          element-loading-text="加载中..."
          :data="this.personList"
          style="width: 100%;margin-bottom: 20px;"
        >
          <el-table-column prop="sourceInfo" label="人像" width="100" align="center">
            <template slot-scope="scope">
              <img
                :src="scope.row.sourceInfo ? scope.row.sourceInfo[0].avatar : ''"
                v-image-preview
                alt
                style="width: 50px; height: 50px;"
              />
            </template>
          </el-table-column>
          <el-table-column prop="name" label="姓名" align="center" width="150">
            <template slot-scope="scope">
              <span v-if="scope.row.name">{{ scope.row.name }}</span>
              <span v-if="!scope.row.name">未知</span>
            </template>
          </el-table-column>
          <el-table-column prop="gender" label="性别" align="center" width="60">
            <template slot-scope="scope">
              <span v-if="scope.row.gender == 1">女</span>
              <span v-if="scope.row.gender == 2">男</span>
              <span v-if="!scope.row.gender">未知</span>
            </template>
          </el-table-column>
          <el-table-column prop="idCard" label="身份证" align="center" width="200">
            <template slot-scope="scope">
              <span v-if="scope.row.idCard">{{ scope.row.idCard }}</span>
              <span v-if="!scope.row.idCard">未知</span>
            </template>
          </el-table-column>
          <el-table-column prop="sourceInfo" label="数据来源" width="150" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.sourceInfo && scope.row.sourceInfo[0].source==1">初始数据</span>
              <span v-if="scope.row.sourceInfo && scope.row.sourceInfo[0].source==2">手机扫码录入</span>
              <span v-if="scope.row.sourceInfo && scope.row.sourceInfo[0].source==3">后台录入</span>
              <span v-if="scope.row.sourceInfo && scope.row.sourceInfo[0].source==4">senseLink平台</span>
            </template>
          </el-table-column>
          <el-table-column prop="sourceInfo" label="人员类型" align="center" width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.sourceInfo && scope.row.sourceInfo[0].type == 1">住户</span>
              <span v-if="scope.row.sourceInfo && scope.row.sourceInfo[0].type == 2">租户</span>
              <span v-if="scope.row.sourceInfo && scope.row.sourceInfo[0].type == 3">物业人员</span>
              <span v-if="scope.row.sourceInfo && scope.row.sourceInfo[0].type == 4">服务人员</span>
              <span v-if="scope.row.sourceInfo && scope.row.sourceInfo[0].type == 5">来访人员</span>
              <span v-if="!scope.row.sourceInfo">未知</span>
            </template>
          </el-table-column>
          <el-table-column prop="sourceInfo[0].updateTime" label="提交时间" align="center" width="250">
            <template slot-scope="scope">
              <span
                v-if="scope.row.sourceInfo[0].updateTime"
              >{{ scope.row.sourceInfo[0].updateTime }}</span>
              <span v-if="!scope.row.sourceInfo[0].updateTime">未知</span>
            </template>
          </el-table-column>
          <el-table-column prop="sourceInfo[0].HID" label="人员地址" align="center"></el-table-column>
          <el-table-column
            fixed="right"
            header-align="center"
            align="center"
            width="200"
            :label="$t('action.operation')"
          >
            <template slot-scope="scope">
              <!-- <el-button size="mini" type="text" @click="seeSubmit(scope.$index, scope.row)">编辑</el-button> -->
              <el-button type="primary" plain size="mini" @click="examineSubmit(scope.$index, scope.row)">审核</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 编辑人员 审核验证 -->
        <el-dialog
          id="userAdd"
          :title="details ? details : '是否通过审核'"
          :visible.sync="dialogTableVisible"
          @close="closeDialog('details')"
        >
          
          <!-- 人员审核 -->
          <el-button type="primary" @click="adopt">通过</el-button>
          <el-button type="danger" @click="refer">未通过</el-button>
          <el-button type="info" @click="Substandard">照片不达标</el-button>
          <el-button @click="cancel">取 消</el-button>
        </el-dialog>
      </div>
      <div slot="footer">
        <el-pagination
          layout="total, prev, pager, next, jumper"
          @current-change="refreshPageRequest"
          :current-page="pageRequest.page"
          :page-size="pageRequest.pageSize"
          :total="totalSize"
          style="float:right;"
        ></el-pagination>
      </div>
    </page>
  </div>
</template>

<script>
export default {
  data() {
    return {
      asideShow: false,
      // unitShow: false,
      pageResult: [],
      filters: {
        corpId: 0,
        corpName: "",
        username: "",
        startTime: "",
        endTime: ""
      },
      pageRequest: {
        page: 1,
        pageSize: 10
      },
      columns: [],
      loading: false,
      totalSize: 0,
      exportUrl: this.global.baseUrl + "/self_test_stat/export",
      exportLoading: false,

      //人员管控数据
      personList: [],
      // 弹框
      details: "",
      dialogTableVisible: false,
      signList: "",
      detailsList: {
        avatar: "",
        type: "",
        person_id: "",
        HID: "",
        name: "",
        HIDD: ""
      },
      // 宽度
      formLabelWidth2: "140px",
      // 人员标记
      getNewList: [],
      marklist: [
        "在家隔离",
        "确诊人员",
        "疑似病例",
        "留守儿童",
        "低保人员",
        "优抚对象",
        "孤寡老人",
        "离休人员",
        "重病人员",
        "残疾人员",
        "留守人员",
        "邪教人员"
      ],
      dialogmarkVisible: false,
      // 人员类型
      options: [
        {
          value: 1,
          label: "住户"
        },
        {
          value: 2,
          label: "租户"
        },
        {
          value: 3,
          label: "物业人员"
        },
        {
          value: 4,
          label: "服务人员"
        },
        {
          value: 5,
          label: "来访人员"
        }
      ],
      // 审核人员
      examineList: {}
    };
  },
  mounted() {
    this.getList(this.pageRequest.page, this.pageRequest.pageSize);
  },
  methods: {
    // 计算年龄
    ages(str) {
      var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
      if (r == null) return false;
      var d = new Date(r[1], r[3] - 1, r[4]);
      if (
        d.getFullYear() == r[1] &&
        d.getMonth() + 1 == r[3] &&
        d.getDate() == r[4]
      ) {
        var Y = new Date().getFullYear();
        return " " + (Y - r[1]) + " 岁";
      }
      return "输入的日期格式错误！";
    },
    // 时间转换
    format(time, format) {
      var t = new Date(time);
      var tf = function(i) {
        return (i < 10 ? "0" : "") + i;
      };
      return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a) {
        switch (a) {
          case "yyyy":
            return tf(t.getFullYear());
            break;
          case "MM":
            return tf(t.getMonth() + 1);
            break;
          case "mm":
            return tf(t.getMinutes());
            break;
          case "dd":
            return tf(t.getDate());
            break;
          case "HH":
            return tf(t.getHours());
            break;
          case "ss":
            return tf(t.getSeconds());
            break;
        }
      });
    },
    // 获取人员列表
    // PCID
    getList(page, limit, name, type, HID, search) {
      // this.loading = true;

      // this.$api.dict.findPageType(paramJson).then((res) => {
        let params={
          PCID: ["511421"],
          page: page,
          limit: limit,
          status: 0,
          name: name,
          type: type,
          // _csrf: this.$store.state.token,
          HID: HID
        }
        // this.$api.personReview.findPage().then((res) =>{

        // })

      this.$http
        .post(this.$ports.personnel.personList, {
          PCID: ["511421"],
          page: page,
          limit: limit,
          status: 0,
          name: name,
          type: type,
          // _csrf: this.$store.state.token,
          HID: HID
        })
        .then(res => {
          this.loading = false;
          // console.log("人员列表", res);
          if (res.code == 0) {
            this.totalSize = res.count;
            this.personList = res.data;
            this.personList.forEach(item => {
              // alert(this.ages(item.birthday))
              //  身份证加密
              item.idCard = item.idCard.replace(
                /(\d{4})\d*([0-9a-zA-Z]{4})/,
                "$1******$2"
              );
              if (item.sourceInfo) {
                item.sourceInfo.forEach(val => {
                  val.avatar =
                    this.$ports.headurl +
                    this.$ports.avatar.imageAvatar +
                    val.CID +
                    "/" +
                    val.avatar;
                  val.updateTime = this.format(
                    val.updateTime,
                    "yyyy-MM-dd HH:mm:ss"
                  );
                  val.HID = val.HID.split("-");
                  item.fHID = val.HID[0] + "-" + val.HID[1] + "-";
                  if (val.HID[2]) {
                    val.HID[2] = val.HID[2] + "栋";
                  } else {
                    val.HID[2] = "";
                  }
                  if (val.HID[3]) {
                    val.HID[3] = val.HID[3] + "单元";
                  } else {
                    val.HID[3] = "";
                  }
                  if (val.HID[4]) {
                    val.HID[4] = val.HID[4] + "楼";
                  } else {
                    val.HID[4] = "";
                  }
                  if (val.HID[5]) {
                    val.HID[5] = val.HID[5] + "号";
                  } else {
                    val.HID[5] = "";
                  }
                  val.HID =
                    //     // this.$store.state.name +
                    val.HID[2] + val.HID[3] + val.HID[4] + val.HID[5];
                  //   // this.address = item.HID;
                });
              }
            });
          }
        })
        .catch(err => {
          console.log("人员列表错误", err);
        });
    },
    // 查找人员类型
    handleClear() {},
    // 姓名查找
    handleQuery() {},
    // 审核人员
    examineSubmit(index, row) {
      this.dialogTableVisible = true;
      // console.log("12313", row);
      this.examineList.source_id = row.source_ids[0];
      this.examineList.CID = row.CID;
      // console.log("1222222",row.CID)
    },
    // 审核通过
    adopt() {
      // let index = this.indexS;
      // let id = this.tableData[index]._id;
      // console.log(id, "id名");
      // let statusA = this.tableData[index].status;
      this.$http
        .post(this.$ports.pass.personReview, {
          // _csrf: this.$store.state.token,
          source_id: this.examineList.source_id,
          status: 1,
          CID: this.examineList.CID
        })
        .then(res => {
          if (res.code == 0) {
            this.$message({
              type: "success",
              message: "审核通过"
            });
            this.dialogTableVisible = false;
            this.examineList = {};
            this.getList(this.pageRequest.page, this.pageRequest.pageSize);
          }
        });
    },
    // 审核不通过
    refer() {
      this.$http
        .post(this.$ports.pass.personReview, {
          // _csrf: this.$store.state.token,
          source_id: this.examineList.source_id,
          status: 2,
          CID: this.examineList.CID
        })
        .then(res => {
          if (res.code == 0) {
            this.$message({
              type: "info",
              message: "审核不通过"
            });
            this.dialogTableVisible = false;
            // this.examineList = {};
            this.getList(this.pageRequest.page, this.pageRequest.pageSize);
          }
        });
    },
    // 照片不达标
    Substandard() {
      console.log("jjjjj",this.examineList.CID)
      this.$http
        .post(this.$ports.pass.personReview, {
          // _csrf: this.$store.state.token,
          source_id: this.examineList.source_id,
          status: 2,
          CID: this.examineList.CID,
        })
        .then(res => {
          console.log("照片不搭边",res)
          if (res.code == 0) {
            this.$message({
              type: "info",
              message: "照片不到标"
            });
            this.dialogTableVisible = false;
            this.getList(this.pageRequest.page, this.pageRequest.pageSize);
          }
        });
    },
    // 取消按钮
    cancel() {
      this.dialogTableVisible = false;
    },
    // 编辑人员
    // seeSubmit(index, row) {

    //   // 地址处理
    //   var cid = "510199";
    //   this.details = "人员编辑";
    //   this.dialogTableVisible = true;
    //   this.detailsList.avatar = row.sourceInfo[0].avatar;
    //   this.detailsList.name = row.name;
    //   this.detailsList.person_id = row._id;
    //   this.detailsList.type = row.sourceInfo[0].type;
    //   this.detailsList.HID = row.sourceInfo[0].HID;
    //     var ld = this.detailsList.HID.replace("栋", "-");
    //     var dy = ld.replace("单元", "-");
    //     var lc = dy.replace("楼", "-");
    //     var hh = "510100-001-" + lc.replace("号", "");
    //     this.detailsList.HIDD = row.fHID+hh;
    //     // console.log("地址",row.fHID)
    // },
    // 确认修改
    // fixSubmit(formRest){
    //   this.$http.post(this.$ports.pass.personUpdate,{
    //     person_id:this.detailsList.person_id,
    //     name:this.detailsList.name,
    //     type:this.detailsList.type,
    //     HID:this.detailsList.HIDD
    //   }).then(res=>{
    //     console.log("徐该人员",res)
    //   }).catch(err=>{console.log("修改人员错误",err)})
    // },
    // 取消
    cancelSubmit(formRest) {
      this.dialogTableVisible = false;
      this.$refs[formRest].resetFields();
    },
    //x按钮
    closeDialog() {
      this.dialogTableVisible = false;
    },
    // 标记
    signSubmit(index, row) {
      this.dialogmarkVisible = true;
    },
    // 删除
    deletePer(index, row) {},
    // 翻页
    refreshPageRequest(val) {
      this.pageRequest.page = val;
      this.getList(this.pageRequest.page, this.pageRequest.pageSize);
    }
  }
};
</script>

<style lang="scss" scoped>
.el-select {
  width: 100%;
}
</style>